package com.sumer.brain.common.model;

import com.sumer.brain.sys.model.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class SecurityUser implements UserDetails {

    private final SysUser sysUser;

//    private String authorities;

    public SecurityUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    public Long getId() {
        return sysUser.getUserId();
    }

    /**
     * 授予用户的权限
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    /**
     * 用户的密码（当前密码是经过加密后的）
     */
    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getUsername();
    }

    /**
     * 用户的账号是否过期true 未过期 false 已过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 用户的账号是否被锁定true 未被锁定 false 被锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        return sysUser.getLockFlag().equals(0);
    }

    /**
     * 用户的凭据（密码）是否已过期true 未过期 false 已过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 用户是否启用true 启用 false 禁用
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
